from selenium import webdriver
import time
import os
import unittest
from public.url import wkurl
from public.wklogin import wklogin


class Test_XLR(unittest.TestCase):
    def setUp(self):
        self.driver=webdriver.Chrome()
        url=wkurl(self.driver).test_url()
        self.driver.get(url+"/index.html#/login?redirect=%2F404")
        self.driver.maximize_window()
        time.sleep(3)
        print("start_time"+time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime(time.time())))

    def tearDown(self):
        file_dir="D:/test/screenshot/"
        if not os.path.exists(file_dir):
            os.makedirs(os.path.join("D:/","test","screenshot"))
        print("end_time"+time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime(time.time())))
        screen_name=file_dir+time.strftime("%Y-%m-%d-%H-%M-%S",time.localtime(time.time()))+".png"
        self.driver.get_screenshot_as_file(screen_name)
        self.driver.quit()


    def testLxr_01(self):
        '''点击联系人能否进入联系人页面'''
        wklogin(self.driver).login()
        self.driver.find_element_by_link_text('客户管理').click()
        time.sleep(6)
        self.driver.find_element_by_link_text("联系人").click()
        time.sleep(4)
        a=self.driver.find_element_by_xpath("//span[text()='新建联系人']").text

        self.assertEqual("新建联系人",a)

    def testLxr_02(self):
        '''能否成功新建联系人'''
        wklogin(self.driver).login()
        self.driver.find_element_by_link_text('客户管理').click()
        time.sleep(8)
        self.driver.find_element_by_link_text("联系人").click()
        time.sleep(4)
        self.driver.find_element_by_xpath("//span[text()='新建联系人']").click()
        time.sleep(2)
        mz=time.strftime("%Y%m%d%H%M%S",time.localtime(time.time()))
        self.driver.find_element_by_xpath('//form/div[1]/div/div/input').send_keys(mz)
        self.driver.find_element_by_class_name("add-item").click()
        time.sleep(2)
        self.driver.find_element_by_xpath('//div[@class="table-footer"]/../div[2]/div[3]/table/tbody/tr[2]/td/div/label/span/span').click()
        self.driver.find_element_by_xpath('//span[text()="确定"]').click()
        time.sleep(1)
        self.driver.find_element_by_xpath("//div[@class='handle-bar']/button[2]/span[text()='保存']").click()
        time.sleep(2)
        self.driver.refresh()
        time.sleep(2)
        b=self.driver.find_element_by_xpath('//div/div[4]/div[2]/table/tbody/tr[1]/td[2]/div').text

        self.assertEqual(mz,b)

    def testLxr_03(self):
        '''能否成功导出联系人'''
        wklogin(self.driver).login()
        self.driver.find_element_by_link_text('客户管理').click()
        time.sleep(8)
        self.driver.find_element_by_link_text("联系人").click()
        time.sleep(4)
        self.driver.find_element_by_xpath("//div[4]/div[2]/table/tbody/tr[2]/td[1]/div/label/span/span").click()
        time.sleep(2)
        self.driver.find_element_by_xpath("//div[text()='导出选中']").click()
        time.sleep(2)
        a=self.driver.find_element_by_xpath("//span[text()='导出联系人']").text

        self.assertEqual("导出联系人",a)

















if __name__ == "__main__":
    unittest.main()


